package sktit.practice.jpaint.shape;

import java.util.ArrayList;

import org.eclipse.swt.graphics.Point;

public class Ellipse extends AbstractShape {

	protected Point vertex;
	protected int width;
	protected int height;

	public Ellipse(Point aVertex, int aWidth, int aHeight) {
		setVertex(aVertex);
		setWidth(aWidth);
		setHeight(aHeight);
	}

	@Override
	public double getPerimeter() {
		return Math.PI
				* (3 * (getWidth() + getHeight()) / 2.0 - Math
						.sqrt((3 * getWidth() + getHeight())
								* (getWidth() + 3 * getHeight())) / 2.0);
	}

	@Override
	public double getArea() {
		return Math.PI * getWidth() * getHeight() * (1.0 / 4);
	}

	@Override
	public Point[] getBorder() {
		ArrayList<Point> border = new ArrayList<Point>();
		border.add(getVertex());
		border.add(new Point(getVertex().x + getWidth(), getVertex().y));
		border.add(new Point(getVertex().x + getWidth(), getVertex().y
				+ getHeight()));
		border.add(new Point(getVertex().x, getVertex().y + getHeight()));
		return (Point[]) border.toArray();
	}

	public void setVertex(Point vertex) {
		this.vertex = vertex;
	}

	public Point getVertex() {
		return vertex;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getWidth() {
		return width;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getHeight() {
		return height;
	}

}
